/**
* 通用js
* @hyh 整理，收集
* 浙江公众信息产业有限公司
* 调用：
* <script language="javascript" src="../../common/js/zjpii_common.js"></script>
*/

/**
 * JS的trim
 * 作者：Jacky Chen
 * 时间：2008-01-23
 * @param {Object} str
 */
function trimStr(str) { 
 var re = /\s*(\S[^\0]*\S)\s*/; 
 re.exec(str); 
 return RegExp.$1; 
}

/**
 * 将HTML中的表格（Table）转换到Excel中的通用JavaScript函数
 * 作者：Jacky Chen
 * 时间：2008-01-23
 * 说明：通过启动用户本地的Excel，将网页上的指定HTML表格导出到Excel中。
 * 能够根据HTML单元格的行列扩展信息自动进行Excel单元格的合并。
 * 参数说明：
 * tableID 是要导出表格的 id
 * rowStart 是跳过的行数
 * colStart 是跳过的列数
 * 使用范例：  ConvertToExcel("TableId",0,0);
 * @param {Object} tableID
 * @param {Object} rowStart
 * @param {Object} colStart
 */
function ConvertToExcel(tableID, rowStart ,colStart){
  var xlApp,myWorkbook,myWordsheet,myHTMLTableCell,myExcelCell,myExcelCell2;
  var myCellColSpan,myCellRowSpan;
  try{
    xlApp=new ActiveXObject("Excel.Application");
  }
  catch(e){
    alert("无法启动Excel!\n\n"+e.message+"\n\n如果您确信您的电脑中已经安装了Excel，那么请调整IE的安全级别。\n\n将IE--工具-->Internet选项-->安全-->自定义级别-->\n\n“对没有标记为安全的ActiveX控件进行初始化和脚本运用”设置为启用！");
    return false;
  }
  xlApp.Visible=true;
  myWorkbook=xlApp.Workbooks.Add();
  xlApp.DisplayAlerts=false;
  myWorkbook.Worksheets(3).Delete();
  myWorkbook.Worksheets(2).Delete();
  xlApp.DisplayAlerts=true;
  myWorksheet=myWorkbook.ActiveSheet;
  var obj = document.all.tags("table");
  var RealColCount;  //实际列数（通过HTML表格的第二行得到）
  RealColCount=0;
  for(x=0;x<obj.length;x++)
  {
    if(obj[x].id==tableID)
    {
      for (i=rowStart; i<obj[x].rows.length; i++)
      {
        for (j=colStart; j<obj[x].rows(i).cells.length; j++){
          myExcelCell=myWorksheet.Cells(i+1-rowStart,j+1-colStart);
          myHTMLTableCell=obj[x].rows(i).cells(j)
          myExcelCell.Value = myHTMLTableCell.innerText;
          myCellColSpan = myHTMLTableCell.colSpan;
          myCellRowSpan = myHTMLTableCell.rowSpan;
          //不是第一行，且有合并单元格的情况
          if((i>rowStart)&&(myCellColSpan*myCellRowSpan>1)){
            myExcelCell2=myWorksheet.Cells(i+1-rowStart+(myCellRowSpan-1),j+1-colStart+(myCellColSpan-1));
            myWorksheet.Range(myExcelCell,myExcelCell2).Merge();
          }
          if(i==rowStart+1)
          RealColCount=RealColCount+myCellColSpan;
        }
      }
      //如果有标题栏（第一个有效行的单元格数量为1），则处理标题栏的合并情况
      if((obj[x].rows(rowStart).cells.length==1)&&(RealColCount>0)){
        myExcelCell=myWorksheet.Cells(1,1);
        myExcelCell2=myWorksheet.Cells(1,RealColCount);
        myWorksheet.Range(myExcelCell,myExcelCell2).Merge();
      }
    }
  }
  myWorksheet.Columns("A:IV").AutoFit;
}

/**
 * 获得提示的HTML
 * @author Jacky Chen
 * 2007-11-16
 * @param {Object} infoMsg
 */
function getInfoHTML(infoMsg){
	var str = "<table width=\"325\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"jiagou_chu\">";
	str += "<tr><td colspan=\"3\"><img src=\"../../themes/blue/images/error1_01.gif\"></td></tr>";
	str += "<tr>";
	str += "<td width=\"5\" background=\"../../themes/blue/images/error1_02.gif\"></td>";
	str += "<td width=\"315\" valign=\"top\"><table width=\"315\" height=\"103\"  border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
	str += "<tr>";
	str += "<td height=\"17\" colspan=\"3\">&nbsp;</td>";
	str += "</tr>";
	str += "<tr>";
	str += "<td width=\"8%\" height=\"33\">&nbsp;</td>";
	str += "<td colspan=\"2\"><img src=\"../../themes/blue/images/error1_08.jpg\"></td>";
	str += "</tr>";
	str += "<tr>";
	str += "<td height=\"49\">&nbsp;</td>";
	str += "<td width=\"10%\">&nbsp;</td>";
	str += "<td width=\"82%\">"+infoMsg+"</td>";
	str += "</tr>";
	str += "</table></td>";
	str += "<td width=\"5\" background=\"../../themes/blue/images/error1_04.gif\"></td>";
	str += "</tr>";
	str += "<tr>";
	str += "<td colspan=\"3\"><table width=\"325\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
	str += "<tr>";
	str += "<td valign=\"bottom\"><table width=\"220\" height=\"118\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
	str += "<tr>";
	str += "<td width=\"5\" height=\"107\" background=\"../../themes/blue/images/error1_02.gif\"></td>";
	str += "<td width=\"213\">&nbsp;</td>";
	str += "</tr>";
	str += "<tr>";
	str += " <td height=\"5\" colspan=\"2\"><img src=\"../../themes/blue/images/error1_13.gif\"></td>";
	str += "</tr>";
	str += "</table></td>";
	str += "<td width=\"109\"><img src=\"../../themes/blue/images/error1_12.gif\"></td>";
	str += "</tr>";
	str += "</table></td>";
	str += "</tr>";
	str += "</table>";
	return str;
}
//**************************************************
//作者：hyh(hyyyer@gmail.com)
//创建日期：2007-6-20
//功能：访问地址
//**************************************************
function goUrl(/*String*/ url){
    document.location.href = url;
}
//**************************************************
//作者：hyh(hyyyer@gmail.com)
//创建日期：2007-11-20
//功能：回退
//**************************************************
function back(){
	history.go(-1);
}
//**************************************************
//作者：hyh,pxw(hyyyer@gmail.com)
//创建日期：2007-6-20
//功能：是否选择checkbox
//**************************************************

function checkItem(/**/checkboxName){ 
       var idArray = document.getElementsByName(checkboxName);
       var isChecked = false;
       var ids = "";
       for (var i = 0 ; i < idArray.length ; i++){
         if(idArray[i].checked){
           isChecked = true;
           break;
         }
       }
       if(!isChecked){
         alert("请至少选择一条记录!");
         return false;
       }
       //组装提交链
       for(var i = 0 ; i < idArray.length ; i++ ){
       		if(idArray[i].checked){
       			if(ids == ""){
					ids = idArray[i].value;
				}else{
					ids += "_"+idArray[i].value;
				}
       		}
       	}
       	return ids;
       //去掉最后的"&id="
       id = id.substring(0,id.length - 4);
       /**
       if(info == null){
       		info = "你确定删除吗？";
       }
       if(confirm(info)){
       	    window.location.href=url + id;
       }else{
       	    void(0);
       } 
       */
}
	
//**************************************************
//作者：hyh(hyyyer@gmail.com)
//创建日期：2007-6-23
//功能：全选
//**************************************************
function chooseAll(checkboxes){
       var e = window.event.srcElement;
       var checkBoxArray = document.getElementsByName(checkboxes);
       for (var i = 0 ; i < checkBoxArray.length ; i++){
         if (e.checked){
           checkBoxArray[i].checked = true;
         }else {
         	checkBoxArray[i].checked = false;
         }
       }
}
//**************************************************
//作者：hyh(hyyyer@gmail.com)
//创建日期：2007-11-23
//功能：通用查询全选
//**************************************************
function checkAll(){
	var ischecked=document.getElementById('chkall').checked;
	i=1;
	name="chkbox"+i;
	while(document.getElementById(name)!=null){
		chkbox=document.getElementById(name);
		chkbox.checked=ischecked;
		i++;
		name="chkbox"+i;
	}
}
//**************************************************
//作者：hyh(hyyyer@gmail.com)
//创建日期：2007-11-23
//功能：通用查询取得选中checkvalue 组装
//**************************************************
function getCheckValues(){
	var ids ="";
	i=1;
	name="chkbox" + i;
	while(document.getElementById(name) != null){
		chkbox=document.getElementById(name);
		if(chkbox.checked){
			if(ids == ""){
				ids = chkbox.value;
			}else{
				ids += "_"+chkbox.value
			}
		}
		i++;
		name="chkbox"+i;
	}
	return ids;
}
//getCheckValuesByName
function getCheckValuesByName(checkboxName){ 
       var idArray = document.getElementsByName(checkboxName);
       var ids = "";
       for(var i = 0 ; i < idArray.length ; i++ ){
       		if(idArray[i].checked){
       			if(ids == ""){
					ids = idArray[i].value;
				}else{
					ids += "_"+idArray[i].value;
				}
       		}
       	}
       	return ids;
}

//**************************************************
//作者：hyh(hyyyer@gmail.com)
//创建日期：2007-6-21
//功能：取得多选框选中的所有值，并返回ids
//**************************************************
function getSlectValues(ids,selId){
	 var sel = document.getElementById(selId);
  	 for(i=0;i<sel.length;i++){
		if(sel.options[i].selected){
			if(ids == ""){
				ids = sel.options[i].value;
			}else{
				ids = ids + "_" + sel.options[i].value ;
			}
		}
	  }
	  return ids;
}

//**************************************************
//作者：hyh
//创建日期：2007-9-20
//功能：显示/隐藏 section层
//**************************************************
function openOrCloseSectionLayout(id){
      var sectionDiv = document.getElementById('sectionDiv_'+id);
      var section = document.getElementById('section_'+id);
      if(sectionDiv!=null){
  	  	if(sectionDiv.style.display=="inline"){
  	    	sectionDiv.style.display="none";
  	    	if(section != null){
  	    		section.src='../../images/title_open.gif';
  	    	}
  	    }else{
  	    	sectionDiv.style.display="inline";
  	    	if(section != null){
  	    		section.src='../../images/title_close.gif';
  	    	}
        }
      }
} 

//**************************************************
//作者：hyh(hyyyer@gmail.com)
//创建日期：2007-11-27
//功能：弹出模态窗口
//<html><base target="_self"><body>
//**************************************************
function openQueryWindow(/*String*/url,/*Object*/para,/*int*/width,/*int*/height){
  	var paraArray = para.split(",");
  	var array = new Array(paraArray.length);
  	for(var i=0;i<paraArray.length; ++i){
  		array[i]= document.getElementById(paraArray[i]);
  	}
  	window.showModalDialog(url,array,'dialogWidth:'+width+'px;dialogHeight:'+height+'px;center:yes;status:no');
}
//**************************************************
//作者：hyh(hyyyer@gmail.com)
//创建日期：2007-11-27
//功能：弹出IE窗口
//**************************************************
function openNormalWindow(newUrl,width,height) {
	var left = (screen.width - width)/2;
	var top = (screen.height - height)/2;
	style="toolbar=no,location=no,directories=no,status=no,resizable=yes,scrollbars=yes,left="+left+",top="+top+",width="+width+",height="+height;
	var w_personSelect=window.open(newUrl, "", style);
	return false;
} 


//**************************************************
//作者：pxw
//创建日期：2007-7-4
//功能：字符长度转化,长度不足两位前面加"0"
//**************************************************
function convertLength(obj){
  	if(obj.toString().length == 1){
  		obj = "0" + obj;
  	}
  	return obj;
}

//**************************************************
//作者：pxw
//创建日期：2007-7-5
//功能：显示或者隐藏某区域
//**************************************************
function showOrHidden(obj){
  	var objArray = document.getElementsByName(obj);
  	var objArray_1 = document.getElementsByName(obj + "_1");
  	if(objArray_1[0].style.display == "none"){
  		for(var i = 0 ; i < objArray.length ; i++ ){
  			objArray[i].style.display = "none";
  		}
  		for(var i = 0 ; i < objArray_1.length ; i++ ){
  			objArray_1[i].style.display = "inline";
  		}
  	}else{
  		for(var i = 0 ; i < objArray.length ; i++ ){
  			objArray[i].style.display = "inline";
  		}
  		for(var i = 0 ; i < objArray_1.length ; i++ ){
  			objArray_1[i].style.display = "none";
  		}
	}
  	//for(var i = 0 ; i < objArray.length ; i++ ){
  		//if(objArray[i].style.display == "inline"){
  			//objArray[i].style.display = "none";
  		//}else{
  			//objArray[i].style.display = "inline";
  		//}
  	//}
}
//**************************************************
//作者：pxw
//创建日期：2007-7-16
//功能：dwr回调函数(下拉框专用)
//说明：data,服务器端返回数据 obj1,页面下拉框ID obj2,下拉框初始化参数,如果不需要该参数，那就传个null obj3,是否加'["请选择......"]'项,true:加,false:不加
//**************************************************
function callBackMethod(data,obj1,obj2,obj3){
  	var id = $(obj1);
	DWRUtil.removeAllOptions(id);
	obj3==true?(DWRUtil.addOptions(id, ["请选择......"])):0==0;
        DWRUtil.addOptions(id,data,"elem_id","elem_name");
        (obj2==null || obj2==0)?0==0:(DWRUtil.setValue(id,obj2));	
}

//**************************************************
//作者：pxw
//创建日期：2007-07-20
//功能：是否选择checkbox
//**************************************************

function checkItems(){ 
       var idArray = document.getElementsByName("ids");
       var isChecked = false;
       var id = "";
       for (var i = 0 ; i < idArray.length ; i++){
         if(idArray[i].checked){
           isChecked = true;
           break;
         }
       }
       if(!isChecked){
         alert("请至少选择一条记录!");
         return false;
       }
       //组装提交链
       for(var i = 0 ; i < idArray.length ; i++ ){
       		if(idArray[i].checked){
       			id = id + idArray[i].value + "&workform_id=";
       		}
       	}
       //去掉最后的"&workform_id="
       id = id.substring(0,id.length - 13);
       return id;
}

//**************************************************
//作者：pxw
//创建日期：2007-08-15
//功能：获取当前日期(格式：yyyy-MM-dd HH:mm:ss)
//**************************************************
function getCurrentDate(){
	 var time = new Date();
   	 var year = time.getYear();//年
   	 var month = convertLength(time.getMonth()+1);//月
   	 var date = convertLength(time.getDate());//日
   	 var hours = convertLength(time.getHours());//时
	 var minutes = convertLength(time.getMinutes());//分
	 var seconds = convertLength(time.getSeconds());//秒
	 var theCurrentDay = year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds;
	 return theCurrentDay;
}

//**************************************************
//作者：hyh
//创建日期：2007-08-15
//功能：格式化时间(格式：yyyy-MM-dd HH:mm:ss)
//**************************************************
function formatDate(time,type){
	 if(time == null || time == "" || time == "null") return "";
   	 var year = time.getYear();//年
   	 var month = time.getMonth()+1;//月
   	 var date = time.getDate();//日
   	 if(type == "date"){
   	 	var theCurrentDay = year + "-" + month + "-" + date;
   	 }else if(type == "cndate"){
   	 	 var theCurrentDay = year + "年" + month + "月" + date + "日";
   	 }else{
   	 	var hours = time.getHours();//时
	 	var minutes = time.getMinutes();//分
	 	var seconds = time.getSeconds();//秒
	 	var theCurrentDay = year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds;
   	 }
	 return theCurrentDay;
}
//**************************************************
//作者：hyh
//创建日期：2007-11-13
//功能：格式化时间,string转date
//**************************************************
function strToDate(str){
   if(str == "") return "";
   var dt = str.split(" ");
   if(dt[1] == null || dt[1] == "" ||dt[1] == undefined){//2007-11-15
   	   var d = dt[0].split("-");
   	   var d_date = new Date(d[0],d[1]-1,d[2],0,0,0);
       return d_date;
   }else{//2007-11-15 14:28:46
   	   var d = dt[0].split("-");
   	   var t = dt[1].split(":");
   	   var d_date = new Date(d[0],d[1]-1,d[2],t[0],t[1],t[2]);
       return d_date;
   }
}
//**************************************************
//作者：hyh
//创建日期：2008-01-24
//功能：查今天是星期几
//**************************************************
function getDayOfWeek(dayValue){//dayValue空为今天
	if(dayValue == null || dayValue == "" || typeof(dayValue) == "undefined"){
		var day = new Date();
	}else{
		var day = new Date(Date.parse(dayValue.replace(/-/g, '/'))); //将日期值格式化
	}
    var today = new Array("星期天","星期一","星期二","星期三","星期四","星期五","星期六");
    return today[day.getDay()] //day.getDay();根据Date返一个星期中的某一天，其中0为星期日
}
//**************************************************
//作者：hyh
//创建日期：2008-01-24
//功能：日期相加减
//**************************************************
function dateOp(op,strInterval,dtTmp,number){
	if(op == "+"){
		switch (strInterval) {    
        	case 's' :return new Date(Date.parse(dtTmp) + (1000 * number));   
        	case 'n' :return new Date(Date.parse(dtTmp) + (60000 * number));   
        	case 'h' :return new Date(Date.parse(dtTmp) + (3600000 * number));   
        	case 'd' :return new Date(Date.parse(dtTmp) + (86400000 * number));   
        	case 'w' :return new Date(Date.parse(dtTmp) + ((86400000 * 7) * number));   
        	case 'q' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + number*3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());   
        	case 'm' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());   
        	case 'y' :return new Date((dtTmp.getFullYear() + number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());   
    	}
	}else{
		switch (strInterval) {    
        	case 's' :return new Date(Date.parse(dtTmp) - (1000 * number));   
        	case 'n' :return new Date(Date.parse(dtTmp) - (60000 * number));   
        	case 'h' :return new Date(Date.parse(dtTmp) - (3600000 * number));   
        	case 'd' :return new Date(Date.parse(dtTmp) - (86400000 * number));   
        	case 'w' :return new Date(Date.parse(dtTmp) - ((86400000 * 7) * number));   
        	case 'q' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) - number*3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());   
        	case 'm' :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) - number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());   
        	case 'y' :return new Date((dtTmp.getFullYear() - number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());   
    	}
	}
}
//**************************************************
//作者：hyh
//创建日期：2007-09-30
//功能：div换行
//**************************************************
function toBreakWord(intLen, id){
 var obj=document.getElementById(id);
 var strContent=obj.innerHTML;
 var strTemp="";
 while(strContent.length>intLen){
  strTemp+=strContent.substr(0,intLen)+"<br>";
  strContent=strContent.substr(intLen,strContent.length);
 }
 strTemp+= strContent;
 obj.innerHTML=strTemp;
}

//**************************************************
//作者：hyh
//创建日期：2007-09-30
//功能：replaceAll
//**************************************************
String.prototype.replaceAll = function(pattern, text, ignoreCase){
	if(RegExp.prototype.isPrototypeOf(pattern))
	throw new Error("Not supported. Use \"g\" flag with regExp patterns.");
	return this.replace(new RegExp(pattern, (ignoreCase === true ? "gi" : "g")), text);
}

//**************************************************
//作者：Jacky Chen
//创建日期：2007-11-21
//功能：JS获得request中的值 只用于URL和GET方式的FORM
//**************************************************
function JSRequest(name){   
  new RegExp("(^|&)"+name+"=([^&]*)").exec(window.location.search.substr(1));
  return RegExp.$2   
}

//**************************************************
//作者：hyh
//创建日期：9:31 2007-11-30
//功能：窗口关闭
//**************************************************
function closeWin() {
	window.close();
	/**
    if (window.confirm("您查看的网页正在试图关闭窗口。\n\n是否关闭此窗口?")){
    	this.close();
    }
    */
}

//@see next js is for html form 

/*
  addOption(obj, name, value)
  参数:obj  select对象
      name  选项名称
      value 选项值
  功能:添加下拉框选项
*/
function addOption(obj, name, value)
{
	var optionObj = new Option(name, value);
  	obj.add(optionObj);
}

/*
  delOptions(obj)
  参数:obj  select对象
  功能:删除下拉框所有选项
*/
function delOptions(obj)
{
  for(i=0; i<obj.length; i++)
  {
     obj.remove(0);
  }
}

/*
  selectedOption(obj, value)
  参数:obj  select对象
      value 选项值
  功能:设置值为value的选项默认选中
*/
function selectedOption(obj, value)
{
  for(i=0; i<obj.length; i++)
  {
    if (obj.options[i].value == value)
    {
      obj.options[i].selected = true;
    }
  }
}

/*
  getRadioGroupValue(objName)
  参数:objName  radioGroupName
  返回值：radioGroup的选中值
  功能:获取radioGroup的选中值
*/
function getRadioGroupValue(objName)
{
  for(i=0; i<document.getElementsByName(objName).length; i++)
  {
    if (document.getElementsByName(objName)[i].checked == true)
    {
      return document.getElementsByName(objName)[i].value;
    }
  }
}



//@see next js funciton if for js_util
function ran(R){		
	return Math.floor((R+1)*Math.random())
}

//@see next js function is for table change color hyh
var arrayOfRolloverClasses = new Array();
var arrayOfClickClasses = new Array();
var activeRow = false;
var activeRowClickArray = new Array();
	
function highlightTableRow(){
	var tableObj = this.parentNode;
	if(tableObj.tagName!='TABLE')tableObj = tableObj.parentNode;
	if(this!=activeRow){
		this.setAttribute('origCl',this.className);
		this.origCl = this.className;
	}
	this.className = arrayOfRolloverClasses[tableObj.id];
	activeRow = this;
}

function clickOnTableRow(){
	var tableObj = this.parentNode;
	if(tableObj.tagName!='TABLE')tableObj = tableObj.parentNode;		
	if(activeRowClickArray[tableObj.id] && this!=activeRowClickArray[tableObj.id]){
		activeRowClickArray[tableObj.id].className='';
	}
	this.className = arrayOfClickClasses[tableObj.id];
	activeRowClickArray[tableObj.id] = this;
}

function resetRowStyle(){
	var tableObj = this.parentNode;
	if(tableObj.tagName!='TABLE')tableObj = tableObj.parentNode;
	if(activeRowClickArray[tableObj.id] && this==activeRowClickArray[tableObj.id]){
		this.className = arrayOfClickClasses[tableObj.id];
		return;	
	}
	var origCl = this.getAttribute('origCl');
	if(!origCl)origCl = this.origCl;
	this.className=origCl;
}

function addTableRolloverEffect(tableId,whichClass,whichClassOnClick){
	arrayOfRolloverClasses[tableId] = whichClass;
	arrayOfClickClasses[tableId] = whichClassOnClick;
	var tableObj = document.getElementById(tableId);
	var tBody = tableObj.getElementsByTagName('TBODY');
	if(tBody){
		var rows = tBody[0].getElementsByTagName('TR');
	}else{
		var rows = tableObj.getElementsByTagName('TR');
	}
	for(var no=0;no<rows.length;no++){
		rows[no].onmouseover = highlightTableRow;
		rows[no].onmouseout = resetRowStyle;	
		if(whichClassOnClick){
			rows[no].onclick = clickOnTableRow;	
		}
	}
}
//addTableRolloverEffect('myTable','tableRollOverEffect1','tableRowClickEffect1');

//@see next js function is for table sort hyh
var tableWidget_okToSort = true;
var tableWidget_arraySort = new Array();
tableWidget_tableCounter = 1;
var activeColumn = new Array();
var arrowImagePath = "../themes/default/images/";
var currentColumn = false;
function sortNumeric(a,b){
	a = a.replace(/,/,'.');
	b = b.replace(/,/,'.');
	a = a.replace(/[^\d\.\/]/g,'');
	b = b.replace(/[^\d\.\/]/g,'');
	if(a.indexOf('/')>=0)a = eval(a);
	if(b.indexOf('/')>=0)b = eval(b);
	return a/1 - b/1;
}
	
function sortString(a, b) {
  if ( a.toUpperCase() < b.toUpperCase() ) return -1;
  if ( a.toUpperCase() > b.toUpperCase() ) return 1;
  return 0;
}

function sortTable(){
	if(!tableWidget_okToSort)return;
	tableWidget_okToSort = false;
	/* Getting index of current column */
	var obj = this;
	var indexThis = 0;
	while(obj.previousSibling){
		obj = obj.previousSibling;
		if(obj.tagName=='TD')indexThis++;
	}
	if(this.getAttribute('direction') || this.direction){
		direction = this.getAttribute('direction');
		if(navigator.userAgent.indexOf('Opera')>=0)direction = this.direction;
		if(direction=='ascending'){
			direction = 'descending';
			this.setAttribute('direction','descending');
			this.direction = 'descending';	
		}else{
			direction = 'ascending';
			this.setAttribute('direction','ascending');
			this.direction = 'ascending';		
		}
	}else{
		direction = 'ascending';
		this.setAttribute('direction','ascending');
		this.direction = 'ascending';
	}
	var images = this.getElementsByTagName('IMG');
	if(direction=='descending'){
		images[0].style.display='inline';
		images[0].style.visibility='visible';
		images[1].style.display='none';
	}else{
		images[1].style.display='inline';
		images[1].style.visibility='visible';
		images[0].style.display='none';
	}
	var tableObj = this.parentNode.parentNode.parentNode;
	var tBody = tableObj.getElementsByTagName('TBODY')[0];
	var widgetIndex = tableObj.getAttribute('tableIndex');
	if(!widgetIndex)widgetIndex = tableObj.tableIndex;
	if(currentColumn)currentColumn.className='';
	document.getElementById('col' + widgetIndex + '_' + (indexThis+1)).className='highlightedColumn';
	currentColumn = document.getElementById('col' + widgetIndex + '_' + (indexThis+1));
	var sortMethod = tableWidget_arraySort[widgetIndex][indexThis]; // N = numeric, S = String
	if(activeColumn[widgetIndex] && activeColumn[widgetIndex]!=this){
		var images = activeColumn[widgetIndex].getElementsByTagName('IMG');
		images[0].style.display='none';
		images[1].style.display='inline';
		images[1].style.visibility = 'hidden';
		if(activeColumn[widgetIndex])activeColumn[widgetIndex].removeAttribute('direction');
	}
	activeColumn[widgetIndex] = this;
	var cellArray = new Array();
	var cellObjArray = new Array();
	for(var no=1;no<tableObj.rows.length;no++){
		var content= tableObj.rows[no].cells[indexThis].innerHTML+'';
		cellArray.push(content);
		cellObjArray.push(tableObj.rows[no].cells[indexThis]);
	}
	if(sortMethod=='N'){
		cellArray = cellArray.sort(sortNumeric);
	}else{
		cellArray = cellArray.sort(sortString);
	}
	if(direction=='descending'){
		for(var no=cellArray.length;no>=0;no--){
			for(var no2=0;no2<cellObjArray.length;no2++){
				if(cellObjArray[no2].innerHTML == cellArray[no] && !cellObjArray[no2].getAttribute('allreadySorted')){
					cellObjArray[no2].setAttribute('allreadySorted','1');
					tBody.appendChild(cellObjArray[no2].parentNode);
				}
			}
		}
	}else{
		for(var no=0;no<cellArray.length;no++){
			for(var no2=0;no2<cellObjArray.length;no2++){
				if(cellObjArray[no2].innerHTML == cellArray[no] && !cellObjArray[no2].getAttribute('allreadySorted')){
					cellObjArray[no2].setAttribute('allreadySorted','1');
					tBody.appendChild(cellObjArray[no2].parentNode);
				}
			}
		}
	}
	for(var no2=0;no2<cellObjArray.length;no2++){
		cellObjArray[no2].removeAttribute('allreadySorted');		
	}
	tableWidget_okToSort = true;
}
function initSortTable(objId,sortArray){
	var obj = document.getElementById(objId);
	if(obj.tableIndex){
		return;
	};
	obj.setAttribute('tableIndex',tableWidget_tableCounter);
	obj.tableIndex = tableWidget_tableCounter;
	tableWidget_arraySort[tableWidget_tableCounter] = sortArray;
	var tHead = obj.getElementsByTagName('THEAD')[0];
	var cells = tHead.getElementsByTagName('TD');
	for(var no=0;no<cells.length;no++){
		if(sortArray[no]){
			cells[no].onclick = sortTable;
			var img = document.createElement('IMG');
			img.src = arrowImagePath + 'arrow_up.gif';
			cells[no].appendChild(img);
			img.style.visibility = 'hidden';			
			var img = document.createElement('IMG');
			img.src = arrowImagePath + 'arrow_down.gif';
			cells[no].appendChild(img);	
			img.style.display = 'none';
		}else{
			cells[no].style.cursor = 'default';	
		}
	}		
	for(var no2=0;no2<sortArray.length;no2++){	/* Right align numeric cells */
		if(sortArray[no2] && sortArray[no2]=='N')obj.rows[0].cells[no2].style.textAlign='right';
	}		
	tableWidget_tableCounter++;
}
//initSortTable('myTable',Array('S','N','S','N','S'));

//next js funtion is for sAlert hyh
function openWin_h(src,w,h){
	var info = "<iframe name=hyh frameBorder=0 width=100% height=100% src='"+src+"'></iframe>";
	sAlert(info,w,h);
}
function sAlert(str,w,h){
	var msgw,msgh,bordercolor;
	if(w==null){
		msgw = 300;
	}else{
		msgw=w;// 提示窗口的宽度
	}
	if(h==null){
		msgh = 100;
	}else{
		msgh=h;// 提示窗口的高度
	}
	titlecolor = "#393c3e";// 提示窗口的边框颜色a7cadd,cfcdaf,5690a1,287798,73878c,242a1b,bdbdbd,3996c6,88beec,adc9f0,abd6e0
	bordercolor = "#eee";//提示窗口的标题颜色99aaff
	var sWidth,sHeight;
	sWidth=document.body.offsetWidth;
	//sWidth=window.screen.availWidth;
	sHeight=document.body.offsetHeight;
	//sHeight=window.screen.availheight;
	var bgObj=document.createElement("div");
	bgObj.setAttribute('id','bgDiv');
	bgObj.style.position="absolute";
	bgObj.style.top="0";
	bgObj.style.background="#777";
	bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
	bgObj.style.opacity="0.6";
	bgObj.style.left="0";
	var hhhh = document.body.offsetHeight;
	bgObj.style.width=document.body.offsetWidth + "px";
	bgObj.style.height=document.body.clientHeight  + "px";
	document.body.appendChild(bgObj);
	var msgObj=document.createElement("div")
	msgObj.setAttribute("id","msgDiv");
	msgObj.setAttribute("align","center");
	msgObj.style.position="absolute";
	msgObj.style.background="white";
	msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
	msgObj.style.border="1px solid " + bordercolor;
	msgObj.style.width=msgw + "px";
	msgObj.style.height=msgh + "px";
	//msgObj.style.top=(document.body.scrollTop + (sHeight-msgh)/2) + "px";
	msgObj.style.top= 60 + "px";
	msgObj.style.left=(sWidth-msgw)/2 + "px";
	var title=document.createElement("h4");
	title.setAttribute("id","msgTitle");
	title.setAttribute("align","right");
	title.style.margin="0";
	title.style.padding="3px";
	title.style.background= titlecolor;
	title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
	title.style.opacity="0.75";
	title.style.border="1px solid " + titlecolor;
	title.style.height="18px";
	title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
	title.style.color="648de1"; 
	title.style.fontWeight="bold";
	title.style.cursor="pointer";
	title.innerHTML="×";
	title.onclick=function(){
		document.body.removeChild(bgObj);
		document.getElementById("msgDiv").removeChild(title);
		document.body.removeChild(msgObj);
	}
	document.body.appendChild(msgObj);
	document.getElementById("msgDiv").appendChild(title);
	var txt=document.createElement("p");
	txt.style.margin="1em 0"
	txt.setAttribute("id","msgTxt");
	txt.innerHTML=str;
	document.getElementById("msgDiv").appendChild(txt);
}
function sClosed(){
	var bgObj = parent.document.getElementById("bgDiv");
	parent.document.body.removeChild(bgObj);
	parent.document.getElementById("msgDiv").removeChild(parent.document.getElementById("msgTitle"));
	parent.document.body.removeChild(parent.document.getElementById("msgDiv"));
	parent.location.reload();
}